package com.b3434.Processor;

import org.apache.avro.generic.GenericRecord;

import java.util.List;

/**
 * Created by Lee on 2017/3/22 0022.
 */
public class SplitProcessor extends Processor {
    Processor processor;
    String[] strs;
    public SplitProcessor(Processor processor) {
        this.processor = processor;
        this.parameter=processor.parameter;

    }
    @Override
    public GenericRecord process(String originStr) {
        dataMap=processor.process(originStr);

        if(parameter.getIsSplited()){
            strs=originStr.split(parameter.getSplitSymbol());

            List<String> fieldNameList = parameter.getFiledNameSplitedList();

            for(int i=0;i<fieldNameList.size();i++){
                dataMap.put(fieldNameList.get(i), strs[i]);
            }
        }

        return dataMap;
    }
}
